package com.example.my_flea_street.controller;

import com.example.my_flea_street.Mapper.UserMapper;
import com.example.my_flea_street.bean.*;
import com.example.my_flea_street.service.UserService;
import com.example.my_flea_street.util.ResponseHelper;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping(value = "/main")
public class MainController {
//    private final UserMapper userMapper;
//
//    @Autowired
//    public MainController(UserMapper userMapper) {
//        this.userMapper = userMapper;
//    }

    private final UserService userService;

    @Autowired
    public MainController(UserService userService) {
        this.userService = userService;
    }

    @RequestMapping(value = "/getUser",method = {RequestMethod.POST,RequestMethod.GET})
    public ResponseEntity<ResponseModel> getAllUser(){
        PageHelper.startPage(1,5);
        PageInfo<Info> pageInfo = new PageInfo<>(userService.getAllUser());
        InfoPage page = new InfoPage();
        page.setTotal((int)pageInfo.getTotal());
        page.setPages(pageInfo.getPages());
        page.setPageNum(pageInfo.getPageNum());
        page.setData(pageInfo.getList());
        return ResponseHelper.createResponse(0, "成功",page);
    }
}
